package gui.utils;

import java.awt.AlphaComposite;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Rectangle;

/**
 * @author Charles Perin
 * 29 mars 2011
 * LIMSI - INRIA Rennes
 * charles.perin@free.fr
 *
 */
public class TransparentRect {

	private Graphics g;
	private float alpha;
	private Rectangle rect;
	private Color color;


	public TransparentRect(Graphics g, float alpha, int x0, int y0, int x1, int y1, Color color){
		this.setG(g);
		this.setAlpha(alpha);
		this.setColor(color);
		this.setRect(new Rectangle(x0, y0, (x1-x0), (y1-y0)));
		drawRect();
	}


	public void drawRect() {
		Graphics2D g2d = (Graphics2D)g;
		g2d.setComposite(makeComposite(this.alpha));
		g2d.setPaint(this.color);
		g2d.fill(this.rect);
	}


	private AlphaComposite makeComposite(float alpha) {
		int type = AlphaComposite.SRC_OVER;
		return(AlphaComposite.getInstance(type, alpha));
	}


	public void setColor(Color color) {
		this.color = color;
	}


	public Color getColor() {
		return color;
	}


	public void setRect(Rectangle rect) {
		this.rect = rect;
	}


	public Rectangle getRect() {
		return rect;
	}


	public void setAlpha(float alpha) {
		this.alpha = alpha;
	}


	public float getAlpha() {
		return alpha;
	}


	public void setG(Graphics g) {
		this.g = g;
	}


	public Graphics getG() {
		return g;
	}
}
